package com.easybuilder.blog.dao;

import com.easybuilder.common.base.dao.BaseDao;
import com.easybuilder.blog.entity.BlogFans;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.ExampleMapper;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface BlogFansDao extends BaseDao<BlogFans>, ExampleMapper<BlogFans> {

    /** 取消关注 */
    @Update("update blog_fans set drop_status = 1 where fans_id = #{fansId} and attention_id = #{userId} and drop_status = 0")
    int cancleAnnotation(Long fansId, Long userId);

    /** 统计当前用户粉丝总量 */
    @Select("select count(1) from blog_fans where attention_id = #{userId} and drop_status = 0")
    Long countFans(Long userId);

    /** 统计当前用户关注总量 */
    @Select("select count(1) from blog_fans where fans_id = #{userId} and drop_status = 0")
    Long countAttention(Long userId);

    /** 粉丝列表分页查询 */
    @Select("select * from blog_fans where attention_id = #{userId} and drop_status = 0 limit #{start}, #{pageSize}")
    List<BlogFans> fansPage(int start, int pageSize, Long userId);

    /** 关注列表分页查询 */
    @Select("select * from blog_fans where fans_id = #{userId} and drop_status = 0 limit #{start}, #{pageSize}")
    List<BlogFans> annotationPage(int start, int pageSize, Long userId);

    @Select("select * from blog_fans where fans_id = #{fansId} and attention_id = #{attentionId}")
    BlogFans selectByFansIdAndAttentionId(Long fansId, Long attentionId);
}